package com.axend.aerosense.pay.ui.adapter;

import android.view.View;

import com.axend.aerosense.common.adapter.BaseBindingAdapter;
import com.axend.aerosense.pay.R;
import com.axend.aerosense.pay.databinding.PayVipPayModeItemBinding;
import com.axend.aerosense.pay.entity.PayModeBean;

import java.util.List;

public class PayVipModeAdapter extends BaseBindingAdapter<PayModeBean, PayVipPayModeItemBinding> {

    private OnItemListener onItemListener;
    private int checkItem = 0;
    private PayModeBean selectItemBean;

    @Override
    protected int getLayoutResId(int viewType) {
        return R.layout.pay_vip_pay_mode_item;
    }

    @Override
    protected void onBindItem(PayVipPayModeItemBinding binding, PayModeBean item, int position) {
        binding.payModeCheckbox.setBackgroundResource(checkItem == position ? R.mipmap.pay_icon_select_true : R.drawable.pay_but_selector_round);
        binding.payModeLayout.setOnClickListener(v -> {
            checkItem = position;

            selectItemBean = item;
            if (onItemListener != null){
                onItemListener.onClick(item, position);
            }

            notifyDataSetChanged();
        });

        if (position == items.size() - 1){
            binding.payModeGuideline.setVisibility(View.GONE);
        }else {
            binding.payModeGuideline.setVisibility(View.VISIBLE);
        }
    }

    public void setData(List<PayModeBean> data){
        if (null != data && !data.isEmpty()){
            upDateList(data);
            selectItemBean = data.get(0);
        }
    }

    public PayModeBean getSelectItemBean() {
        return selectItemBean;
    }

    public void setOnItemListener(OnItemListener onItemListener) {
        this.onItemListener = onItemListener;
    }

    public interface OnItemListener {
        void onClick(PayModeBean item, int pos);
    }

}
